// 消息提示
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus'

class FSMessage {
  public constructor () {
  }

  private loadingInstance;

  /** 描述： 成功提示 */
  public success (msg: string): void {
    ElMessage({
      type: 'success',
      message: msg
    })
  }

  /** 描述： 失败提示 */
  public error (msg: string): void {
    ElMessage({
      type: 'error',
      message: msg
    })
  }

  /** 描述： 消息提示 */
  public info (msg: string): void {
    ElMessage({
      type: 'info',
      message: msg
    })
  }

  /** 描述： 消息提示 */
  public warning (msg: string): void {
    ElMessage({
      type: 'warning',
      message: msg
    })
  }

  /** 描述： 提示确认弹窗 */
  public confirm (msg: string, title: string, cancelBtnText = '取消', confirmBtnText = '确定'): Promise<any> {
    return ElMessageBox.confirm(
      msg,
      title,
      {
        cancelButtonText: cancelBtnText,
        confirmButtonText: confirmBtnText,
        type: 'info'
      }
    )
  }

  public delete (): Promise<any> {
    return ElMessageBox.confirm('删除后不可恢复，是否确认删除？', '提示', {
      type: 'warning',
      cancelButtonText: '取消',
      confirmButtonText: '确认'
    })
  }

  public loading () {
    this.loadingInstance = ElLoading.service({
      text: '加载中',
      lock: true // 加载中禁止滑动页面
    })
  }

  public hideLoading () {
    this.loadingInstance.close()
  }
}

export default new FSMessage()
